from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import reverse,render


class MyMiddleWare(MiddlewareMixin):
    def __init__(self, get_response=None):
        super().__init__(get_response)
        print("init MyMiddleWare")

    def process_request(self, request):
        print('process request')
        request.context = {}
        request.context['login_user'] = None
        if 'login_user' in request.session:
            request.context['login_user'] = request.session.get('login_user')

    def process_response(self, request, response):
        print('process response')
        return response
